package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)
type UserObj struct {
	userPath string
	Users []struct {
		Name   string `json:"name"`
		Type   string `json:"type"`
		Age    int    `json:"age"`
		Social struct {
			Facebook string `json:"facebook"`
			Twitter  string `json:"twitter"`
		} `json:"social"`
	} `json:"users"`
}
func (this *UserObj)SetPath(userPath string) *UserObj {
	this.userPath = userPath
	return this
}

func (this *UserObj) UnmarshalUser() *UserObj {
	userByte ,err := this.ReadUser()
	if err !=nil {
		return this
	}

	err = json.Unmarshal(userByte,this)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(this.Users)
	return this
}

func (this *UserObj)ReadUser() ([]byte, error) {

	data, err := ioutil.ReadFile(this.userPath)
	if err != nil {
		return data, err
	}
	return data, nil
}

func main()  {
	var User UserObj
	User.SetPath("userTest").UnmarshalUser()
}